package com.lq.file.filemanager.controller;

import com.lq.file.filemanager.entity.ResponseBase;
import com.lq.file.filemanager.util.FileServiceUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @program: file-manager
 * @description:
 * @author: LQ
 * @create: 2021-08-07 10:12
 */
@Controller
@ResponseBody
@RequestMapping("/file")
public class FileController {
    @Autowired
    FileServiceUtil serviceUtil;

    @RequestMapping("/uploadFile")
    public ResponseBase uploadFile() {
        return ResponseBase.ok();
    }

    @RequestMapping("/exportFile")
    public ResponseBase exportFile() {
        return ResponseBase.ok();
    }

    @RequestMapping("/readFileToBase64")
    public ResponseBase readFileToBase64() {
        ResponseBase responseBase = new ResponseBase();
        try {
            String result = serviceUtil.getFileService().readFileToBase64( "pdf.pdf","/2021/08/07/");
            responseBase.setResult(result);
            responseBase.setCode(ResponseBase.SUCCESS_CODE);
            return responseBase;
        } catch (Exception e) {
            e.printStackTrace();
            return ResponseBase.fail(e.toString());
        }
    }

}
